package p270jp.pxv.android.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import androidx.databinding.DataBindingUtil;
import p014ae.AbstractActivityC0142q3;
import p014ae.View$OnClickListenerC0054c;
import p014ae.View$OnClickListenerC0151s;
import p014ae.View$OnClickListenerC0158t;
import p047bg.C1124a;
import p056bp.AbstractC1137a;
import p056bp.Instant;
import p056bp.LocalDate;
import p056bp.ZonedDateTime;
import p165fo.Subscribe;
import p270jp.pxv.android.R;
import p270jp.pxv.android.event.DatePickerEvent;
import p270jp.pxv.android.model.ZonedDateTimeConverter;
import p314lg.ActivitySearchDurationCustomBinding;
import p547uh.DatePickerDialogFragment;

/* renamed from: jp.pxv.android.activity.SearchDurationCustomActivity */
/* loaded from: classes2.dex */
public class SearchDurationCustomActivity extends AbstractActivityC0142q3 {

    /* renamed from: P */
    public static final /* synthetic */ int f18650P;

    /* renamed from: M */
    public ActivitySearchDurationCustomBinding f18651M;

    /* renamed from: N */
    public LocalDate f18652N;

    /* renamed from: O */
    public LocalDate f18653O;

    /* renamed from: a1 */
    public final String m4719a1(LocalDate gVar) {
        return getString(R.string.search_duration_date_format, new Object[]{Integer.valueOf(gVar.f5073b), Integer.valueOf(gVar.f5074c), Integer.valueOf(gVar.f5075d)});
    }

    /* renamed from: b1 */
    public final void m4718b1(TextView textView, int i) {
        int paddingTop = textView.getPaddingTop();
        int paddingBottom = textView.getPaddingBottom();
        int paddingLeft = textView.getPaddingLeft();
        int paddingRight = textView.getPaddingRight();
        textView.setBackgroundResource(i);
        textView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    }

    /* renamed from: c1 */
    public final void m4717c1(LocalDate gVar, long j, long j2, int i) {
        DatePickerDialogFragment.m1661f(gVar.f5073b, gVar.f5074c - 1, gVar.f5075d, j, j2, i).show(m11131K0(), "tag");
    }

    /* renamed from: d1 */
    public final void m4716d1(LocalDate gVar) {
        this.f18653O = gVar;
        this.f18651M.f21879r.setText(m4719a1(gVar));
    }

    /* renamed from: e1 */
    public final void m4715e1(LocalDate gVar) {
        this.f18652N = gVar;
        this.f18651M.f21880s.setText(m4719a1(gVar));
    }

    @Override // p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ActivitySearchDurationCustomBinding l1Var = (ActivitySearchDurationCustomBinding) DataBindingUtil.m11369d(this, R.layout.activity_search_duration_custom);
        this.f18651M = l1Var;
        C1124a.m10197Q(this, l1Var.f21881t, R.string.search_duration_select_date);
        this.f18651M.f21880s.setOnClickListener(new View$OnClickListenerC0158t(this, 7));
        this.f18651M.f21879r.setOnClickListener(new View$OnClickListenerC0151s(this, 3));
        if (bundle == null) {
            LocalDate gVar = LocalDate.f5071e;
            AbstractC1137a b = AbstractC1137a.m10143b();
            Instant a = b.mo10142a();
            LocalDate W = LocalDate.m10091W(C1124a.m10180l(a.f5069b + ((long) ((AbstractC1137a.C1138a) b).f5057a.mo9995n().mo5780a(a).f5128b), 86400));
            LocalDate R = W.m10096R(1);
            this.f18652N = R;
            this.f18651M.f21880s.setText(m4719a1(R));
            this.f18653O = W;
            this.f18651M.f21879r.setText(m4719a1(W));
            this.f18651M.f21880s.performClick();
        } else {
            m4715e1((LocalDate) bundle.getSerializable("SAVE_KEY_START_DATE"));
            m4716d1((LocalDate) bundle.getSerializable("SAVE_KEY_END_DATE"));
        }
        this.f18651M.f21878q.setOnClickListener(new View$OnClickListenerC0054c(this, 6));
    }

    @Subscribe
    public void onEvent(DatePickerEvent datePickerEvent) {
        int requestCode = datePickerEvent.getRequestCode();
        LocalDate localDate = datePickerEvent.getLocalDate();
        boolean z = false;
        if (requestCode == 1) {
            this.f18652N = localDate;
            this.f18651M.f21880s.setText(m4719a1(localDate));
            ZonedDateTime Q = ZonedDateTimeConverter.convertToSystemDefault(this.f18652N).m9983Q(1);
            ZonedDateTime convertToSystemDefault = ZonedDateTimeConverter.convertToSystemDefault(this.f18653O);
            int i = (convertToSystemDefault.m7946y() > Q.m7946y() ? 1 : (convertToSystemDefault.m7946y() == Q.m7946y() ? 0 : -1));
            if (i > 0 || (i == 0 && convertToSystemDefault.mo7950C().f5086e > Q.mo7950C().f5086e)) {
                z = true;
            }
            if (z) {
                m4716d1(Q.f5134b.f5078b);
            }
        } else if (requestCode == 2) {
            this.f18653O = localDate;
            this.f18651M.f21879r.setText(m4719a1(localDate));
            ZonedDateTime convertToSystemDefault2 = ZonedDateTimeConverter.convertToSystemDefault(this.f18652N);
            ZonedDateTime Q2 = ZonedDateTimeConverter.convertToSystemDefault(this.f18653O).m9983Q(-1);
            int i2 = (convertToSystemDefault2.m7946y() > Q2.m7946y() ? 1 : (convertToSystemDefault2.m7946y() == Q2.m7946y() ? 0 : -1));
            if (i2 < 0 || (i2 == 0 && convertToSystemDefault2.mo7950C().f5086e < Q2.mo7950C().f5086e)) {
                z = true;
            }
            if (z) {
                m4715e1(Q2.f5134b.f5078b);
            }
        }
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        finish();
        return true;
    }

    @Override // androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putSerializable("SAVE_KEY_START_DATE", this.f18652N);
        bundle.putSerializable("SAVE_KEY_END_DATE", this.f18653O);
    }
}
